home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / SSGame.as < prev    next >
Text File  |  2006-11-29  |  14KB  |  449 lines

  1. class SSGame extends GDK.Base
  2. {
  3.    static var _sinit = SSGame.staticInit();
  4.    static var levels = [];
  5.    static var styles = [];
  6.    static var backgrounds = [];
  7.    static var processStack = new CallStack();
  8.    static var running = false;
  9.    static var ready = false;
  10.    static var currentLevel = 0;
  11.    function SSGame()
  12.    {
  13.       super();
  14.       SSInterface.registerGame(this);
  15.       GDK.EventSubscriber.initObject(SSGame);
  16.       SSGame.setTargetComponent(this);
  17.       SSGame.classes = [];
  18.       SSGame.registerClass(SSShape);
  19.       SSGame.registerClass(SSZone);
  20.       SSGame.registerClass(GameSpring);
  21.       SSGame.registerClass(GamePoint);
  22.       SSGame.registerClass(GameHealth);
  23.       SSGame.registerClass(GameCharacter);
  24.       SSGame.registerClass(Explosive);
  25.       SSGame.registerClass(Checkpoint);
  26.       SSGame.registerClass(CommandBox);
  27.       SSGame.registerClass(DirectionArrow);
  28.       SSGame.registerClass(GameElement);
  29.       SSGame.registerClass(Spikes);
  30.       SSGame.registerClass(GameLife);
  31.       SSGame.registerClass(GameVehicle);
  32.       SSGame.registerClass(WalkingObject);
  33.       SSGame.registerClass(FlyingObject);
  34.       SSGame.registerClass(RopeObject);
  35.       SSGame.registerClass(GameContainer);
  36.       SSGame.registerClass(GameBigPoint);
  37.       SSGame.registerClass(GameHealthBig);
  38.       SSGame.registerClass(RollingObject);
  39.       SSGame.registerClass(FlyingObject);
  40.       SSGame.registerClass(BouncingObject);
  41.       SSGame.registerClass(JumpingFish);
  42.       SSGame.registerClass(GameFuel);
  43.       SSGame.registerClass(GameSwing);
  44.       SSGame.registerClass(VR_HiddenPlatform);
  45.       SSGame.registerClass(VR_EMP);
  46.       SSGame.registerClass(VR_Shield);
  47.       SSGame.registerClass(MessageBox);
  48.       SSGame.registerClass(SSDrawStyle);
  49.       this.addEvent("Pause",this.onGamePause);
  50.       this.addEvent("Resume",this.onGameResume);
  51.       this.baseSound = new Sound(this);
  52.    }
  53.    static function setTargetComponent(mc)
  54.    {
  55.       SSGame.target = mc;
  56.    }
  57.    static function staticInit()
  58.    {
  59.       SSGame.processStack.wait(0.1);
  60.    }
  61.    static function registerClass(cls)
  62.    {
  63.       var _loc1_ = GDK.Tools.lookupClassName(cls);
  64.       if(_loc1_ == null)
  65.       {
  66.          return undefined;
  67.       }
  68.       if(SSGame.classes[_loc1_])
  69.       {
  70.          return undefined;
  71.       }
  72.       cls.className = _loc1_;
  73.       SSGame.classes.push(SSGame.classes[_loc1_] = _loc1_);
  74.    }
  75.    static function loadConfig(url)
  76.    {
  77.       SSGame.processStack.wait(0.01);
  78.       var _loc2_ = new XML();
  79.       _loc2_.ignoreWhite = true;
  80.       _loc2_.onLoad = function()
  81.       {
  82.          this.loaded = true;
  83.       };
  84.       _loc2_.loaded = false;
  85.       SSGame.processStack.call(SSGame,function(x, url)
  86.       {
  87.          x.load(url);
  88.       }
  89.       ,_loc2_,url);
  90.       SSGame.processStack.call(_loc2_,function()
  91.       {
  92.          return this.loaded == true;
  93.       }
  94.       );
  95.       SSGame.processStack.call(SSGame,SSGame.processConfig,_loc2_);
  96.    }
  97.    static function processConfig(data)
  98.    {
  99.       if(typeof data == "string")
  100.       {
  101.          data = new XML(data);
  102.       }
  103.       var _loc2_ = undefined;
  104.       var _loc1_ = -1;
  105.       var _loc3_ = _loc2_ = data.firstChild.childNodes.length;
  106.       while((_loc1_ = _loc1_ + 1) < _loc3_)
  107.       {
  108.          switch(_loc2_[_loc1_].nodeName.toLowerCase())
  109.          {
  110.             case "styles":
  111.                SSGame.processStyles(_loc2_[_loc1_]);
  112.                break;
  113.             case "bg":
  114.                SSGame.processBackgrounds(_loc2_[_loc1_]);
  115.                break;
  116.             case "objects":
  117.                SSGame.processObjects(_loc2_[_loc1_]);
  118.          }
  119.       }
  120.    }
  121.    static function processBackgrounds(data)
  122.    {
  123.       if(typeof data == "string")
  124.       {
  125.          data = new XML(data);
  126.       }
  127.       var _loc13_ = undefined;
  128.       var _loc16_ = data.firstChild;
  129.       if(!_loc16_)
  130.       {
  131.          return undefined;
  132.       }
  133.       var _loc18_ = undefined;
  134.       var _loc15_ = undefined;
  135.       var _loc20_ = undefined;
  136.       var _loc3_ = undefined;
  137.       var _loc17_ = undefined;
  138.       var _loc19_ = undefined;
  139.       var _loc11_ = undefined;
  140.       do
  141.       {
  142.          var _loc0_ = null;
  143.          var _loc21_ = _global[_loc16_.attributes.name] = {layers:_loc20_ = []};
  144.          _loc15_ = _loc18_ = _loc16_.childNodes.length;
  145.          while((_loc15_ = _loc15_ - 1) > -1)
  146.          {
  147.             _loc3_ = _loc18_[_loc15_].attributes;
  148.             if(!(!_loc17_ = _loc3_.tiles.length || !(_loc19_ = Number(_loc3_.z))))
  149.             {
  150.                var _loc9_ = Number(_loc3_.w);
  151.                var _loc12_ = Number(_loc3_.h);
  152.                if(!_loc9_ || !_loc12_)
  153.                {
  154.                   var _loc7_ = _global.root.attachMovie(_loc17_,"TMPBGTEST",987700);
  155.                   if(!_loc7_)
  156.                   {
  157.                      continue;
  158.                   }
  159.                   _loc9_ = _loc7_._width;
  160.                   _loc12_ = _loc7_._height;
  161.                   _loc7_.removeMovieClip();
  162.                }
  163.                _loc20_.push(_loc11_ = new SSBackground(_loc17_,_loc19_,_loc9_,_loc12_,Number(_loc3_.scrollMultiplier)));
  164.                if(!isNaN(_loc13_ = Number(_loc3_.offsetX)))
  165.                {
  166.                   _loc11_.offsetX = _loc13_;
  167.                }
  168.                if(!isNaN(_loc13_ = Number(_loc3_.offsetY)))
  169.                {
  170.                   _loc11_.offsetY = _loc13_;
  171.                }
  172.                _loc11_.stationary = Number(_loc3_.stationary) || _loc3_.stationary == "true" || _loc3_.stationary == "yes";
  173.                var _loc14_ = _loc18_[_loc15_].firstChild.nodeValue;
  174.                var _loc10_ = GDK.Tools.trim;
  175.                if(_loc14_.length > 0)
  176.                {
  177.                   var _loc4_ = undefined;
  178.                   var _loc6_ = undefined;
  179.                   var _loc2_ = _loc14_.split("|");
  180.                   _loc9_ = 0;
  181.                   var _loc5_ = _loc2_.length;
  182.                   while((_loc5_ = _loc5_ - 1) > -1)
  183.                   {
  184.                      if(!_loc2_[_loc5_] = _loc10_(_loc2_[_loc5_]).length)
  185.                      {
  186.                         _loc2_.splice(_loc5_,1);
  187.                      }
  188.                      else
  189.                      {
  190.                         _loc2_[_loc5_] = _loc2_[_loc5_].split(",");
  191.                         _loc4_ = _loc6_ = _loc2_[_loc5_].length;
  192.                         _loc9_ = Math.max(_loc4_,_loc9_);
  193.                         while((_loc4_ = _loc4_ - 1) > -1)
  194.                         {
  195.                            _loc6_[_loc4_] = parseInt(_loc10_(_loc6_[_loc4_]));
  196.                         }
  197.                      }
  198.                   }
  199.                   var _loc8_ = new GDK.Grid(_loc9_,_loc2_.length,!Number(_loc3_.defaultCell) ? 0 : Number(_loc3_.defaultCell));
  200.                   _loc5_ = _loc2_.length;
  201.                   while((_loc5_ = _loc5_ - 1) > -1)
  202.                   {
  203.                      _loc4_ = _loc2_[_loc5_].length;
  204.                      while((_loc4_ = _loc4_ - 1) > -1)
  205.                      {
  206.                         _loc8_.setCell(_loc4_,_loc5_,_loc2_[_loc5_][_loc4_]);
  207.                      }
  208.                   }
  209.                   _loc11_.setPattern(_loc8_);
  210.                }
  211.             }
  212.          }
  213.       }
  214.       while(_loc16_ = _loc16_.nextSibling);
  215.       
  216.    }
  217.    static function processObjects(data)
  218.    {
  219.       if(typeof data == "string")
  220.       {
  221.          data = new XML(data);
  222.       }
  223.       var _loc1_ = data.firstChild;
  224.       if(!_loc1_)
  225.       {
  226.          return undefined;
  227.       }
  228.       var _loc3_ = undefined;
  229.       while(_loc1_ = _loc1_.nextSibling)
  230.       {
  231.       }
  232.    }
  233.    static function processStyles(data)
  234.    {
  235.       if(typeof data == "string")
  236.       {
  237.          data = new XML(data);
  238.       }
  239.       var _loc7_ = data.firstChild;
  240.       if(!_loc7_)
  241.       {
  242.          return undefined;
  243.       }
  244.       var _loc8_ = undefined;
  245.       do
  246.       {
  247.          _loc8_ = _loc7_.attributes;
  248.          if(_loc8_.name != null)
  249.          {
  250.             var _loc0_ = null;
  251.             var _loc9_ = _global[_loc8_.name] = function()
  252.             {
  253.                var _loc3_ = [];
  254.                var _loc2_ = this.__proto__;
  255.                while(_loc2_ = _loc2_.__proto__)
  256.                {
  257.                   _loc3_.push(_loc2_);
  258.                }
  259.                var _loc4_ = _loc3_.length;
  260.                while((_loc4_ = _loc4_ - 1) > -1)
  261.                {
  262.                   _loc3_[_loc4_].constructor.apply(this);
  263.                }
  264.             };
  265.             var _loc5_ = _loc9_.prototype;
  266.             _loc5_.__proto__ = _global[_loc8_.using].prototype;
  267.             if(_loc5_.__proto__ == null)
  268.             {
  269.                _loc5_.__proto__ = SSDrawStyle.prototype;
  270.             }
  271.             _loc5_.className = _loc8_.name;
  272.             _loc5_.styleXML = _loc7_;
  273.          }
  274.       }
  275.       while(_loc7_ = _loc7_.nextSibling);
  276.       
  277.    }
  278.    static function loadLevel(url)
  279.    {
  280.       var _loc3_ = -1;
  281.       var _loc4_ = arguments.length;
  282.       while((_loc3_ = _loc3_ + 1) < _loc4_)
  283.       {
  284.          var _loc2_ = new XML();
  285.          _loc2_.ignoreWhite = true;
  286.          var lev = new SSLevel();
  287.          SSGame.processStack.call(SSGame,function(data, url)
  288.          {
  289.             data.load(url);
  290.          }
  291.          ,_loc2_,arguments[_loc3_]);
  292.          SSGame.processStack.waitUntilEqual(_loc2_,"loaded",true);
  293.          SSGame.processStack.call(lev,lev.readXML,_loc2_);
  294.          SSGame.processStack.waitUntilEqual(lev,"ready",true);
  295.          SSGame.processStack.call(SSGame,function()
  296.          {
  297.             SSGame.levels.push(SSGame.levels[lev.name] = lev);
  298.          }
  299.          ,lev);
  300.       }
  301.    }
  302.    static function processLevel(data)
  303.    {
  304.       var lev = new SSLevel();
  305.       if(typeof data == "string")
  306.       {
  307.          data = new XML(data);
  308.       }
  309.       SSGame.processStack.call(lev,lev.readXML,data);
  310.       SSGame.processStack.waitUntilEqual(lev,"ready",true);
  311.       SSGame.processStack.call(SSGame,function()
  312.       {
  313.          SSGame.levels.push(SSGame.levels[lev.name] = lev);
  314.       }
  315.       ,lev);
  316.    }
  317.    static function processStyle(data)
  318.    {
  319.    }
  320.    static function processBackground(data)
  321.    {
  322.    }
  323.    static function process()
  324.    {
  325.       if(SSGame.running)
  326.       {
  327.          return undefined;
  328.       }
  329.       SSGame.running = true;
  330.       SSGame.processStack.onFinish = function()
  331.       {
  332.          SSGame.ready = true;
  333.          SSGame.onReady();
  334.       };
  335.       SSGame.processStack.start();
  336.       delete SSGame.process;
  337.    }
  338.    function gotoWorld(name, targetNode, char)
  339.    {
  340.       var _loc2_ = this.worlds[name];
  341.       if(_loc2_)
  342.       {
  343.          if(_loc2_ != this.activeWorld)
  344.          {
  345.          }
  346.       }
  347.       else
  348.       {
  349.          this.generateWorld(name,targetNode,char);
  350.       }
  351.    }
  352.    function generateWorld(name, targetNode, char)
  353.    {
  354.       _global.root.levelIntro.show(SSGame.currentLevel);
  355.       var _loc4_ = SSGame.levels[String(name)];
  356.       _loc4_.targetNode = targetNode;
  357.       _loc4_.char = char;
  358.       _loc4_.onComplete = function(base, ssw)
  359.       {
  360.          var _loc3_ = new GameCharacter();
  361.          _loc3_.keepInScene = false;
  362.          ssw.addObject(ssw.character = _loc3_);
  363.          ssw.addPlayer(SSGame.player);
  364.          if(ssw.references[this.targetNode] != null)
  365.          {
  366.             _loc3_.setRestorePoint(ssw.references[this.targetNode]);
  367.             _loc3_.restore();
  368.          }
  369.          base.setActiveWorld(ssw);
  370.          SSGame.player.setControl(_loc3_);
  371.          SSInterface.watchObject(SSGame.player,function(obj)
  372.          {
  373.             this.watchProp(SSGame,"currentLevel",function(prop, oldValue, newValue)
  374.             {
  375.                SSInterface.target[prop] = newValue + 1;
  376.                return newValue;
  377.             }
  378.             );
  379.             this.watchProp(obj,"score",this.textValue);
  380.             this.watchProp(obj,"lives",this.textValue);
  381.             this.watchProp(obj,"fuel",this.meterValue);
  382.             this.watchProp(obj,"shield",this.textValue);
  383.             this.watchProp(obj,"health",this.meterValue);
  384.          }
  385.          );
  386.          GameSound.playMusic(this.music,0.5,true);
  387.          base.start();
  388.          SSInterface.hide();
  389.          _global.root.levelIntro.hide();
  390.       };
  391.       _loc4_.build(this);
  392.    }
  393.    function addMaterial()
  394.    {
  395.    }
  396.    function addShapeStyle()
  397.    {
  398.    }
  399.    static function startNewGame()
  400.    {
  401.       SSGame.player = new GamePlayer();
  402.       SSInterface.hide();
  403.       SSGame.currentLevel = 0;
  404.       if(Key.isDown(17))
  405.       {
  406.          if(Key.isDown(50))
  407.          {
  408.             SSGame.currentLevel = 1;
  409.          }
  410.          else if(Key.isDown(51))
  411.          {
  412.             SSGame.currentLevel = 2;
  413.          }
  414.       }
  415.       SSGame.target.activeWorld = null;
  416.       SSGame.target.removeAllWorlds();
  417.       SSGame.target.gotoWorld(SSGame.levels[SSGame.currentLevel].name,SSGame.levels[SSGame.currentLevel].startNode);
  418.    }
  419.    static function nextLevel()
  420.    {
  421.       if(++SSGame.currentLevel >= SSGame.levels.length)
  422.       {
  423.          SSGame.winGame();
  424.          SSGame.target.removeAllWorlds();
  425.          return undefined;
  426.       }
  427.       _global.root.gotoAndStop("cacheLoad");
  428.       var _loc2_ = SSGame.target.activeWorld.character;
  429.       SSGame.target.gotoWorld(SSGame.levels[SSGame.currentLevel].name,SSGame.levels[SSGame.currentLevel].startNode,_loc2_);
  430.    }
  431.    static function exitLevel()
  432.    {
  433.    }
  434.    static function winGame()
  435.    {
  436.       SSInterface.showScreen("WinGame",true);
  437.    }
  438.    function onGamePause()
  439.    {
  440.       this.baseSound.setVolume(0);
  441.       GameSound.pause();
  442.    }
  443.    function onGameResume()
  444.    {
  445.       this.baseSound.setVolume(100);
  446.       GameSound.resume();
  447.    }
  448. }
  449.